#include <iostream>
#include "hr_time.h"
#include "IpAdressT.h"
using namespace std;

namespace Uppg31
{
	int factorial(int f)
	{
		int sum = 0;
		if (f == 0)
		{
			return 1;
		}
		else
		{
			return sum = f* factorial(f - 1);
		}
	}
	double recursion(int n, int x, int i)
	{
		double sum = 0;
		if (i > n)
		{
			return 0;
		}
		else
		{
			return sum = (x*(pow(-x, 2 * i)) / factorial(2 * i + 1)) + recursion(n, x, i + 1);
		}
	}
	double iterative(int n, int x, int i)
	{
		double sum = 0;
		for (size_t j = i; j < n+1; j++)
		{
			int fac = 1;
			for (size_t k = j; k > 0; k--)
			{
				fac *= (2 * k + 1);
			}
			sum += (x*pow(-x, 2 * i)) / fac;
		}
		return sum;
	}
	void main()
	{
		CStopWatch sw1;
		CStopWatch sw2;
		int numIterations = 1000000;
		int i = 0;
		int x = 5;
		int n = 4;

		sw1.startTimer();
		for (size_t i = 0; i < numIterations; i++)
		{
			recursion(n, x, i);
		}
		sw1.stopTimer();
		sw2.startTimer();
		for (size_t i = 0; i < numIterations; i++)
		{
			iterative(n, x, i);
		}
		sw2.stopTimer();
		cout << "Rec: " << (sw1.getElapsedTime() / numIterations) << endl;
		cout << "Ite: " << (sw2.getElapsedTime() / numIterations) << endl;

	}
}
namespace Uppg32
{
	void main()
	{
		IpAdressT IP;
		IP.readFromFile("ip_three.txt");
		IP.antalUppkoppl("160.125.125.123");
		IP.tenFreq();
	}
}
int main()
{
	//Uppg31::main();
	Uppg32::main();
	cin.get();
	return 0;
}